package com.superhelp.ebill.api.param;


import com.superhelp.ebill.api.ApiConfig;

import java.util.Comparator;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;

import zuo.biao.library.util.SettingUtil;

/**
 * 参数的基类
 * 
 *
 */
public abstract class Params {

	protected TreeMap<String, String> params;

	public TreeMap<String, String> simpleParams() {

		params = new TreeMap<String, String>(new Comparator<String>() {

			@Override
			public int compare(String arg0, String arg1) {
				return arg0.compareTo(arg1);
			}
		});
//		params.put("t", String.valueOf(System.currentTimeMillis()));
		return params;
	}

	/**
	 * 合并参数
	 * 
	 * @return
	 */
	public String convertParam() {
		StringBuffer sb = new StringBuffer();
		if (null != params) {

			Set set = params.entrySet();
			Iterator it = params.entrySet().iterator();
			while (it.hasNext()) {
				Entry entry = (Entry) it.next();
				sb.append(entry.getKey());
				sb.append("=");
				sb.append(entry.getValue());
				sb.append("&");
			}

		}

		sb.append("key=" + ApiConfig.HTTP_KEY);
		return sb.toString();
	}

	public abstract TreeMap<String, String> getParams();

	@Override
	public String toString() {

		return getParams().toString();
	}
}
